/*
 * 作者: 董绘峰
 * 时间: 2017-02-09
 * 说明：
 * Copyright (c) 2016-2017 中研沃兮
 */
define(function(require) {
	require("jquery");
    var c = require('app/utils/CommonUtils');
    var CacheUtils = require('app/utils/CacheUtils');
    var EchoLazyUtils = require('app/utils/EchoLazyUtils');
	var APIUtils = require('app/utils/APIUtils');
	
	var win = window;
	var action = {};
	
	EchoLazyUtils.load();
	
	action.removeOnlineAvatar = function(data){
		var useruuid = data.useruuid;
		var sessionid = data.sessionid;
		var id = sessionid+"_"+useruuid;
		$("#"+id).remove();
	}


	action.addOnlineAvatar = function(data){
		action.removeOnlineAvatar(data);
		var useruuid = data.useruuid;
		var sessionid = data.sessionid;
		var headimgurl = data.headimgurl;
		var id = sessionid+"_"+useruuid;
		var cacheheadimgurl = null;
		var imgdiv = null;
		
		if(c.isNullStr(headimgurl)){
			headimgurl = "../image/user_avatar_default.jpg";
			imgdiv = '<img src="'+headimgurl+'"  class="aui-img-round">';
		}else{
			headimgurl = c.handleUrl(headimgurl);
			//网络地址，缓存图片
			cacheheadimgurl = CacheUtils.imageCache(headimgurl);
			
			if(headimgurl == cacheheadimgurl){//第一次访问远程图片，还未进行缓存
				imgdiv = '<img style="width:100%;height:100%" data-echo="'+headimgurl+'" src="../image/user_avatar_default.jpg"  class="aui-img-round">';
			}else{//数据库中已经存储缓存记录
				imgdiv = '<img style="width:100%;height:100%" src="'+cacheheadimgurl+'"  class="aui-img-round">';
			}
		}
		
		
		var item = $(
			'<li class="avatar_wrap" id="'+id+'">'+
				imgdiv+
			'</li>');
		$("#avatars").prepend(item);
		
		EchoLazyUtils.load();
//		
//		$(".avatar_wrap").click(function(){
//		
//			var name = "RoomUserInfoFrm";
//			api.openFrame({
//				name : name,
//				url : './' + name + '.html',
//				rect : {
//					x : 0,
//					y : 0,
//					w : APIUtils.winW(),
//					h : APIUtils.winH()
//				},
//				bgColor : 'rgba(0,0,0,0.6)',
//				bounces : false
//			});
//		});
		
	}
	
	action.detailsAction = function(){
		alert("查看详情");
	}
	return action;
});